def main():
    import sys
    input = sys.stdin.read().split()
    idx = 0
    t = int(input[idx])
    idx += 1
    for _ in range(t):
        n = int(input[idx])
        idx +=1
        a = list(map(int, input[idx:idx+n]))
        idx +=n
        if n <2:
            print(0)
            continue
        min_val = min(a)
        max_val = max(a)
        print(max_val - min_val)
        
if __name__ == "__main__":
    main()
